
/*
* Copyright (c) 2013 City University of Hongkong.
*                    Cloud computing security group.
* 
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
* 
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* 
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

/*
* ff_graph.h - derived class from graph which is combinational circuit modeled
*              graph that contains flip-flops.
*
* Authors: Xingliang Yuan     
* Emails:  xyuan86@gmail.com
*
*/


#ifndef FF_GRAPH_H
#define FF_GRAPH_H

#include "graph.h"

class ff_graph: public graph
{
protected:

	/*  
    * description: find string in <vector> vertex_set
    * param: 
    * return: find then return index, otherwise return -1
    */
    int find_equal_string(string &str, vector<string> &vertex_set);

    /*  
    * description: build dag, remove duplicated edge in ISPD
    * for each edge, in must be before out in topological order
    * param: 
    * return: 
    */
    void build_dag();

    /*  
    * description: load dag (get edge set, gate_num, ff_num, edge_num)
    * param: 
    * return: 
    */
    void load_dag(char* dag_file);

public:
    unsigned int ff_num;        // total flip-flop number
    unsigned int gate_num;      // total gate number

    unsigned int delay_column;  // number of pca components for gaussian delay
    vector< vector<float> >vertex_delay; // random vertex delay by PCA

    //ff_graph () {};  //uncomment to implement constructor

    /*  
    * description: get edge in /out tp order is valid or not
    * param: 
    * return: 
    */
    bool check_edge_tp(struct edge &e);

    /*  
    * description: load random gate delay for each vertex
    * param: 
    * return: 
    */
    void load_vertex_delay(char* delay_file);

    /*  
    * description: create dag from BENCH itc99 file
    * param: BENCH ffc file and dag file with single src and dist
    * return: 
    */
    void itc_to_dag(char* itc_file, char* dag_file); 

    /*  
    * description: create dag from BENCH ffc file
    * param: BENCH ffc file and dag file with single src and dist
    * return: 
    */
    void ffc_to_dag(char* ffc_file, char* dag_file); 

    /*  
    * description: delay file reformat
    * param: 
    * return: 
    */
    void delay_format(char* delay_file, char* delay_format_file); 

    /*  
    * description: generate gauss delay for vertex and write to delay file
    * param: 
    * return: 
    */
    void to_delay(char* delay_file);

    /*  
    * description: create dag from ISPD net file
    * param: ISPD net file and modeled graph dag file
    * return: 
    */
    void net_to_dag(char* net_file, char* dag_file); 

    /*  
    * description: generate graph by loading parsed benchmark
    * param: 
    * return: true when the job is done
    */
    void gen_graph(char* dag_file, char* delay_file); 

}; // ff_graph class

#endif // FF_GRAPH_H
